package com.hl.card.modular.pack.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hl.card.common.persistence.dao.CreditCardMapper;
import com.hl.card.common.persistence.model.CreditCard;
import com.hl.card.common.util.ResponseData;


@RestController
@RequestMapping("/api/creditCard")
public class CCreditCardController {
    
	@Autowired
	private ResponseData responseData; 
	@Autowired
	private CreditCardMapper creditCardMapper;
	
	@RequestMapping("/getCardNum")
	public Object  getCardNum()
	{
		Map<String,Object> map=new HashMap<String, Object>();
		int count=creditCardMapper.listCount(map);
		responseData.setData(count);
		responseData.setMsg("操作成功");
		responseData.setStatus("1");
		return responseData;
	}
	
	@RequestMapping("/list")
	public Object list(Integer page,Integer size,String phone)
	{
		responseData.setData(null);
		if(StringUtils.isEmpty(phone))
		{
			responseData.setMsg("手机号不能为空");
			responseData.setStatus("0");
			return responseData;
		}
		if(page==null||"".equals(page))
		{
			page=1;
		}
		if(size==null||"".equals(size))
		{
			size=10;
		}
		Integer start=size*(page-1);
		Map<String,Object> map=new HashMap<String, Object>();
		map.put("offset", start);
		map.put("size", size);
		map.put("phone", phone);
		List<CreditCard> list=creditCardMapper.recommendList(map);
		int total_count=creditCardMapper.getTotalCount(map);
		int active_total_count=creditCardMapper.getTotalActiveCount(map);
		Map<String,Object> result=new HashMap<String, Object>();
		result.put("list", list);
		result.put("total_count", total_count);
		result.put("active_total_count", active_total_count);
		responseData.setData(result);
		responseData.setMsg("操作成功");
		responseData.setStatus("1");
		return responseData;
	}
	
	@RequestMapping("/safeList")
	public Object safeList(Integer page,Integer size,String phone)
	{
		responseData.setData(null);
		if(StringUtils.isEmpty(phone))
		{
			responseData.setMsg("手机号不能为空");
			responseData.setStatus("0");
			return responseData;
		}
		if(page==null||"".equals(page))
		{
			page=1;
		}
		if(size==null||"".equals(size))
		{
			size=10;
		}
		Integer start=size*(page-1);
		Map<String,Object> map=new HashMap<String, Object>();
		map.put("offset", start);
		map.put("size", size);
		map.put("phone", phone);
		List<CreditCard> list=creditCardMapper.safeRecommendList(map);
		int total_count=creditCardMapper.getSafeTotalCount(map);
		int active_total_count=creditCardMapper.getSafeTotalActiveCount(map);
		Map<String,Object> result=new HashMap<String, Object>();
		result.put("list", list);
		result.put("total_count", total_count);
		result.put("active_total_count", active_total_count);
		responseData.setData(result);
		responseData.setMsg("操作成功");
		responseData.setStatus("1");
		return responseData;
	}
}
